package com.huangcy.gulimall.seckill.scheduled;

import ch.qos.logback.core.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.slf4j.XSlf4j;
import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskSchedulingProperties;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @program: gulimall
 * @description:
 * @author: huangcy
 * @create: 2022-09-20 10:19
 **/
//@Slf4j
@Component
//@EnableScheduling
//@EnableAsync  //开启异步任务功能
public class HelloSchedule {


    /**
     * 1、Spring中6位组成,不允许第7位的年
     * 2、在周几的位置，1-7代表周一到周日：MON-SUN
     * 3、定时任务不应该阻塞。默认是阻塞的
     * 1)、可以让业务运行以异步的方式，自己提交到线程池
     * CompletableFuture.runAsync(() -> {
     * xxxService.hello();
     * }, executor)
     * 2)、支持定时惹怒我线程池：设置TaskSchedulingProperties
     * task:
     * scheduling:
     * pool:
     * size: 5
     * 3）、让定时任务异步执行
     */
    @Async
    @Scheduled(cron = "* * * ? * 5")
    public void hello() throws InterruptedException {
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        System.out.println(df.format(System.currentTimeMillis() + "==hello"));
    }
}
